home *** CD-ROM | disk | FTP | other *** search
/ Programming Microsoft Visual Basic .NET / Programming Microsoft Visual Basic .NET (Microsoft Press)(X08-78517)(2002).bin / setup / vbnet / 12 regular expressions / exprevaluator / form1.vb < prev    next >
Encoding:
Text File  |  2002-03-16  |  4.1 KB  |  108 lines

  1. Public Class Form1
  2.     Inherits System.Windows.Forms.Form
  3.  
  4. #Region " Windows Form Designer generated code "
  5.  
  6.     Public Sub New()
  7.         MyBase.New()
  8.  
  9.         'This call is required by the Windows Form Designer.
  10.         InitializeComponent()
  11.  
  12.         'Add any initialization after the InitializeComponent() call
  13.  
  14.     End Sub
  15.  
  16.     'Form overrides dispose to clean up the component list.
  17.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  18.         If disposing Then
  19.             If Not (components Is Nothing) Then
  20.                 components.Dispose()
  21.             End If
  22.         End If
  23.         MyBase.Dispose(disposing)
  24.     End Sub
  25.     Friend WithEvents Label1 As System.Windows.Forms.Label
  26.     Friend WithEvents txtExpression As System.Windows.Forms.TextBox
  27.         Friend WithEvents btnEval As System.Windows.Forms.Button
  28.     Friend WithEvents txtResult As System.Windows.Forms.TextBox
  29.  
  30.     'Required by the Windows Form Designer
  31.     Private components As System.ComponentModel.Container
  32.  
  33.     'NOTE: The following procedure is required by the Windows Form Designer
  34.     'It can be modified using the Windows Form Designer.  
  35.     'Do not modify it using the code editor.
  36.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  37.         Me.Label1 = New System.Windows.Forms.Label()
  38.         Me.btnEval = New System.Windows.Forms.Button()
  39.         Me.txtExpression = New System.Windows.Forms.TextBox()
  40.         Me.txtResult = New System.Windows.Forms.TextBox()
  41.         Me.SuspendLayout()
  42.         '
  43.         'Label1
  44.         '
  45.         Me.Label1.Location = New System.Drawing.Point(8, 8)
  46.         Me.Label1.Name = "Label1"
  47.         Me.Label1.Size = New System.Drawing.Size(248, 24)
  48.         Me.Label1.TabIndex = 0
  49.         Me.Label1.Text = "Enter an expression"
  50.         '
  51.         'btnEval
  52.         '
  53.         Me.btnEval.Location = New System.Drawing.Point(472, 32)
  54.         Me.btnEval.Name = "btnEval"
  55.         Me.btnEval.Size = New System.Drawing.Size(56, 24)
  56.         Me.btnEval.TabIndex = 3
  57.         Me.btnEval.Text = "&Eval"
  58.         '
  59.         'txtExpression
  60.         '
  61.         Me.txtExpression.Location = New System.Drawing.Point(8, 32)
  62.         Me.txtExpression.Multiline = True
  63.         Me.txtExpression.Name = "txtExpression"
  64.         Me.txtExpression.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
  65.         Me.txtExpression.Size = New System.Drawing.Size(456, 64)
  66.         Me.txtExpression.TabIndex = 1
  67.         Me.txtExpression.Text = ""
  68.         '
  69.         'txtResult
  70.         '
  71.         Me.txtResult.BackColor = System.Drawing.Color.WhiteSmoke
  72.         Me.txtResult.Font = New System.Drawing.Font("Microsoft Sans Serif", 12!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  73.         Me.txtResult.ForeColor = System.Drawing.Color.SteelBlue
  74.         Me.txtResult.Location = New System.Drawing.Point(8, 120)
  75.         Me.txtResult.Name = "txtResult"
  76.         Me.txtResult.Size = New System.Drawing.Size(456, 26)
  77.         Me.txtResult.TabIndex = 2
  78.         Me.txtResult.Text = ""
  79.         '
  80.         'Form1
  81.         '
  82.         Me.AcceptButton = Me.btnEval
  83.         Me.AutoScaleBaseSize = New System.Drawing.Size(8, 19)
  84.         Me.ClientSize = New System.Drawing.Size(536, 173)
  85.         Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnEval, Me.txtResult, Me.txtExpression, Me.Label1})
  86.         Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 12!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
  87.         Me.Name = "Form1"
  88.         Me.Text = "Expression Evaluator"
  89.         Me.ResumeLayout(False)
  90.  
  91.     End Sub
  92.  
  93. #End Region
  94.  
  95.     Private Sub btnEval_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEval.Click
  96.         ' evaluate the selected or entire portion of txtSource
  97.         Dim expr As String = txtExpression().SelectedText
  98.         If expr = "" Then expr = txtExpression().Text
  99.         If expr = "" Then Exit Sub
  100.  
  101.         Try
  102.             txtResult.Text = Evaluate(expr).ToString
  103.         Catch ex As Exception
  104.             txtResult.Text = ex.Message
  105.         End Try
  106.     End Sub
  107. End Class
  108.